//
//  LeftDrawerViewController.m
//  TravelOcean
//
//  Created by double Mac on 15/3/7.
//  Copyright (c) 2015年 double Mac. All rights reserved.
//

#import "LeftDrawerViewController.h"
#import "JVFloatingDrawerViewController.h"

static const CGFloat kJVTableViewTopInset = 80.0;

@interface LeftDrawerViewController ()

@end

@implementation LeftDrawerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor greenColor];
    
    // c
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.contentInset = UIEdgeInsetsMake(kJVTableViewTopInset, 0.0, 0.0, 0.0);
    self.clearsSelectionOnViewWillAppear = NO;
    self.tableView.separatorStyle = NO;
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
}

#pragma mark - Table View 数据

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

#pragma mark -- 设置section字体大小, 颜色
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)];
    
    UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor redColor];
    headerLabel.highlightedTextColor = [UIColor whiteColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:20];
    
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (orientation == UIInterfaceOrientationPortraitUpsideDown || orientation == UIInterfaceOrientationPortrait)
    {
        headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);
    }
    else {
        headerLabel.frame = CGRectMake(30.0, -10.0, 300.0, 44.0);
    }

    headerLabel.frame = CGRectMake(100.0, 0.0, 300.0, 44.0);
    
    headerLabel.text = @"畅游海扬";
    headerLabel.font = [UIFont systemFontOfSize:22];
    [customView addSubview:headerLabel];
    
    return customView;
}

#pragma mark -- section顶部间隔
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section
{
    return 70;
}

#pragma mark -- section高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellIndf = @"cell";
    UITableViewCell *cell = nil;
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndf];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//取消cell点击效果
    
    if(indexPath.row == 0) {
        cell.textLabel.text = @"  热门景点";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont systemFontOfSize:20];
        cell.imageView.image = [UIImage imageNamed:@"665-gear@3x.png"];
    }
    if(indexPath.row == 1) {
        cell.textLabel.text = @"  精选游记";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont systemFontOfSize:20];
        cell.imageView.image = [UIImage imageNamed:@"488-github@3x.png"];
    }
    if(indexPath.row == 2) {
        cell.textLabel.text = @"  旅游圈";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont systemFontOfSize:20];
        cell.imageView.image = [UIImage imageNamed:@"665-gear@3x.png"];
    }
    if(indexPath.row == 3) {
        cell.textLabel.text = @"  心灵之旅";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont systemFontOfSize:20];
        cell.imageView.image = [UIImage imageNamed:@"488-github@3x.png"];
    }
    if(indexPath.row == 4) {
        cell.textLabel.text = @"  欢乐旅途";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont systemFontOfSize:20];
        cell.imageView.image = [UIImage imageNamed:@"665-gear@3x.png"];
    }
    if(indexPath.row == 5) {
        cell.textLabel.text = @"  我的收藏";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont systemFontOfSize:20];
        cell.imageView.image = [UIImage imageNamed:@"488-github@3x.png"];
    }
    if(indexPath.row == 6) {
        cell.textLabel.text = @"  关于软件";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont systemFontOfSize:20];
        cell.imageView.image = [UIImage imageNamed:@"488-github@3x.png"];
    }
    
    cell.backgroundColor = [UIColor clearColor];
    
    return cell;
}

#pragma mark -- cell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *destinationViewController = nil;
    
    if(indexPath.row == 0) {
        destinationViewController = [[AppDelegate globalDelegate] hotSpotsViewController];
    }
    
    if(indexPath.row == 1) {
        destinationViewController = [[AppDelegate globalDelegate] rootViewController];
    }
    
    // 切换中心视图
    [[[AppDelegate globalDelegate] drawerViewController] setCenterViewController:destinationViewController];
    [[AppDelegate globalDelegate] toggleLeftDrawer:self animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
